#ifndef __EV_SCENE_DATA_H__
#define __EV_SCENE_DATA_H__


#include<stdint.h>
#include"TimePoint.hpp"
#include"rapidjson/document.h"
#include"rapidjson/stringbuffer.h"
#include"rapidjson/writer.h"

namespace SC_SUN
{

struct EvSceneData
{

    ////////初始历元//////
    TimePoint mStartTime;

    ////////结束历元/////
    TimePoint mEndTime;

    ///////仿真信息//////
    double ST_TT;                                               ///< 总时长

    //////星座信息//////
    uint16_t CST_NUM;                                           ///< 星座数量
    uint16_t SAT_NUM;                                           ///< 卫星总数量

    //用于将必要的数据转换成json字符串
    rapidjson::Document ObjToJsonObject()
    {
        using namespace rapidjson;
        Document doc;
        doc.SetObject();

        doc.AddMember(Value("JD_MS", doc.GetAllocator()), Value(mStartTime.JD), doc.GetAllocator());

        Value value(kArrayType);
        value.PushBack(mStartTime.YY, doc.GetAllocator());
        value.PushBack(mStartTime.MM, doc.GetAllocator());
        value.PushBack(mStartTime.DD, doc.GetAllocator());
        value.PushBack(mStartTime.HH, doc.GetAllocator());
        value.PushBack(mStartTime.MI, doc.GetAllocator());
        value.PushBack(mStartTime.SS, doc.GetAllocator());
        doc.AddMember(Value("UTC_start", doc.GetAllocator()), value, doc.GetAllocator());

        doc.AddMember(Value("JD_ME", doc.GetAllocator()), Value(mEndTime.JD), doc.GetAllocator());
        Value value1(kArrayType);
        value1.PushBack(mEndTime.YY, doc.GetAllocator());
        value1.PushBack(mEndTime.MM, doc.GetAllocator());
        value1.PushBack(mEndTime.DD, doc.GetAllocator());
        value1.PushBack(mEndTime.HH, doc.GetAllocator());
        value1.PushBack(mEndTime.MI, doc.GetAllocator());
        value1.PushBack(mEndTime.SS, doc.GetAllocator());
        doc.AddMember(Value("UTC_end", doc.GetAllocator()), value1, doc.GetAllocator());

        doc.AddMember(Value("ST_TT", doc.GetAllocator()), Value(ST_TT), doc.GetAllocator());
        doc.AddMember(Value("CST_NUM", doc.GetAllocator()), Value(CST_NUM), doc.GetAllocator());
        doc.AddMember(Value("SAT_NUM", doc.GetAllocator()), Value(SAT_NUM), doc.GetAllocator());

        return doc;
    }

    //将json转换为场景数据
    static EvSceneData JsonObjectToObj(const rapidjson::Document& doc)
    {
        EvSceneData ret;

        auto obj = doc.GetObj();
        ret.mStartTime.JD = obj["JD_MS"].GetDouble();
        ret.mStartTime.YY = obj["UTC_start"].GetArray()[0].GetUint();
        ret.mStartTime.MM = obj["UTC_start"].GetArray()[1].GetUint();
        ret.mStartTime.DD = obj["UTC_start"].GetArray()[2].GetUint();
        ret.mStartTime.HH = obj["UTC_start"].GetArray()[3].GetUint();
        ret.mStartTime.MI = obj["UTC_start"].GetArray()[4].GetUint();
        ret.mStartTime.SS = obj["UTC_start"].GetArray()[5].GetUint();

        ret.mEndTime.JD = obj["JD_ME"].GetDouble();
        ret.mEndTime.YY = obj["UTC_end"].GetArray()[0].GetUint();
        ret.mEndTime.MM = obj["UTC_end"].GetArray()[1].GetUint();
        ret.mEndTime.DD = obj["UTC_end"].GetArray()[2].GetUint();
        ret.mEndTime.HH = obj["UTC_end"].GetArray()[3].GetUint();
        ret.mEndTime.MI = obj["UTC_end"].GetArray()[4].GetUint();
        ret.mEndTime.SS = obj["UTC_end"].GetArray()[5].GetUint();

        ret.ST_TT = obj["ST_TT"].GetDouble();
        ret.CST_NUM = obj["CST_NUM"].GetUint();
        ret.SAT_NUM = obj["SAT_NUM"].GetUint();

        return ret;
    }
};

}

#endif